package trong.gold.soft.com.view.help;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import trong.gold.soft.com.main.*;
import trong.gold.soft.com.model.ResizeImage;
import trong.gold.soft.com.model.Resources;
import trong.gold.soft.com.model.font.VietnameseFont;

public class ScrollableTextCanvas extends Canvas
{
	ScrollableTextFieldExt field = null;
	private mTetrisMidlet midlet;
	private Image ktin;
	private String back = "Trở lại";
	private String huongdan = "Hướng dẫn chơi";
	public ScrollableTextCanvas(mTetrisMidlet midlet)
	{
		this.setFullScreenMode(true);
		this.midlet = midlet;
		this.field = new ScrollableTextFieldExt(this.getWidth(), this.getHeight()/2);
		ktin = new ResizeImage().resize(Resources.imgoto, getWidth(),110);
		this.field.setText("Tetris là game xếp gạch cổ điển được phát triển lên nhằm tạo cho người chơi thấy hứng thú hơn và chơi vui hơn với các cửa chơi khác nhau.");
	}
	protected void keyPressed(int key)
	{
		int keyAction = getGameAction(key);
		
		if(keyAction == Canvas.UP)
		{
			this.field.scrollUp();
			
			repaint();
		}
		else if(keyAction == Canvas.DOWN)
		{
			this.field.scrollDown();
			
			repaint();
		}
	}
	
	protected void paint(Graphics g)
	{
		for(int i=0;i<=this.getWidth()/44;i++){
			g.drawImage(Resources.backgr, i*Resources.backgr.getWidth(), 0, Resources.TOP_LEFT_ANCHOR);
		}
		g.drawImage(Resources.imgicon, this.getWidth()/2 - Resources.imgicon.getWidth()/2, 10, Resources.TOP_LEFT_ANCHOR);
		g.drawImage(ktin, this.getWidth()/2 - ktin.getWidth()/2, this.getHeight()/2 - ktin.getHeight()/2, Resources.TOP_LEFT_ANCHOR);
		VietnameseFont.BlackBold.DrawString(g, huongdan,this.getWidth()/2 - VietnameseFont.BlackBold.getWidth(huongdan)/2, this.getHeight()/2 - ktin.getHeight()/2 + VietnameseFont.WhiteBold.getHeight(), Graphics.LEFT);
		VietnameseFont.BlackBold.DrawString(g, back,this.getWidth()/2, this.getHeight() - VietnameseFont.WhiteBold.getHeight(), Graphics.HCENTER);
		

		g.translate( this.getWidth()/2 - ktin.getWidth()/2 +12, this.getHeight()/2 - ktin.getHeight()/2 + 2*VietnameseFont.WhiteBold.getHeight());
		
		this.field.paint(g);
		
		g.translate(-20, -20);
	}
	
}
